import {baseUrl,request} from '../utils/request.js'

const apiUrl = {
	updatePhone:'/user/updatePhone',
	updateUserInfo:'/user/updateUserInfo',
	getCode:'/user/code',
	uploadImg:'/file/uploadImg',
	logOut:'/user/logout',
	loginByPhone:'/user/loginByPhone',
	identityAuthn:'/user/identityAuthn'
}

export function updatePhone(data){
	return request(apiUrl.updatePhone, 'PUT', data)
}

export function updateUserInfo(data){
	return request(apiUrl.updateUserInfo, 'PUT', data)
}

export function getCode(data){
	return request(`${apiUrl.getCode}?phone=${data}`, 'POST')
}

// export function uploadImg(data){
// 	return request(`${apiUrl.uploadImg}?locationCode=${data[0].locationCode}`, 'POST', data[1])
// }
export function uploadImg(locationCode, img) {
	let userInfo = uni.getStorageSync('userInfo');
	let token = uni.getStorageSync('token');
    return new Promise((resolve, reject) => {
        uni.uploadFile({
            url: baseUrl + apiUrl.uploadImg,
            filePath: img,
            name: 'img',
            formData: {
                locationCode: locationCode,
            },
			header: {
				"Content-Type": "multipart/form-data",
				"token": token
			},
			success: (res) => {
			  resolve(res);
			},
			fail: (err) => {
				console.log(err)
				reject(err);
			}
        });
    });
}



export function logOut(data){
	return request(apiUrl.logOut, 'GET', data)
}

export function loginByPhone(data){
	return request(apiUrl.loginByPhone, 'POST', data)
}

export function identityAuthn(data){
	return request(apiUrl.identityAuthn, 'POST', data)
}